import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.MyApplication;
import com.heeexy.example.entity.SysUser;
import com.heeexy.example.util.IpUtil;
import com.heeexy.example.util.constants.ErrorEnum;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApplication.class)
public class test {


    public static void main(String[] args) {

        String query_jsonstr = "{\"timezone\":\"GMT+0\",\"action\":\"front_BRAND\",\"format\":\"true\",\"lan\":\"en_us\",\"column\":[\"day\",\"impressions\",\"clicks\",\"ctr\",\"brand_estimated_ecpm\",\"pay_out\"],\"dimension\":[\"day\"],\"filter\":{\"posid\":{\"op\":\"in\",\"value\":\"2454105\"}},\"start\":1528761600000,\"end\":1529452800000}";
        JSONObject query = JSON.parseObject(query_jsonstr);

        if (query.getJSONObject("filter") != null) {
            JSONObject posJson = new JSONObject();
            posJson.put("op", "in");
            posJson.put("value", "2454117");
            query.getJSONObject("filter").put("posid", posJson);
        }
        String posid = query.getJSONObject("filter").getJSONObject("posid").getString("value");
        String newJsonStr = query.toJSONString();
        System.out.println(newJsonStr);
    }
    @Test
    public void a(){
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        System.out.println(uuid);
    }
    @Test
    public void b(){
        int a=1,b=2;
        int sum = a+b;
        System.out.println(sum);
    }

//    @Test
//    public void c(HttpServletRequest httpServletRequest){
//        String ipAddr = IpUtil.getIpAddr(httpServletRequest);
//        System.out.println(ipAddr);
//    }
@Autowired
HttpServletRequest request;

    @Test
    public void getToken() {
        String token = request.getHeader("token");
        if (StringUtils.isEmpty(token)) {
            token = request.getParameter("token");
        }
        if (StringUtils.isEmpty(token)) {
//            throw new NoveControllerException(ResultEnum.NO_TOKEN.getStrCode(), ResultEnum.NO_TOKEN.getDesc());
            throw new RuntimeException(String.valueOf(ErrorEnum.E_501));
        }
        System.out.println(token);
    }
    /**
     * 得到登录用户ID
     * @return
     */
//    public void getLoginUserId(){
//        String token = getToken();
//        System.out.println(token);
//        SysUser sysUser = new SysUser();
//
//    }
}
